package com.common.www.config.rabbit;

import com.common.www.data.global.RabbitEnum;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author : JCccc
 * @CreateTime : 2019/9/3
 * @Description :
 **/
@Configuration
public class DirectRabbitConfig {

    //======================================队列 起名：TestDirectQueue
    @Bean
    public Queue TestDirectQueue() {
        return new Queue(RabbitEnum.TEST_ORDER.getQueue(), true);  //true 是否持久
    }

    //Direct交换机 起名：TestDirectExchange
    @Bean
    DirectExchange TestDirectExchange() {
        return new DirectExchange(RabbitEnum.TEST_ORDER.getExchange());
    }

    //绑定  将队列和交换机绑定, 并设置用于匹配键：TestDirectRouting
    @Bean
    Binding bindingTestDirect() {
        return BindingBuilder.bind(TestDirectQueue()).to(TestDirectExchange()).with(RabbitEnum.TEST_ORDER.getRouting());
    }

    //=====================================token管理机制
    @Bean
    public Queue TokenDirectQueue() {
        return new Queue(RabbitEnum.TOKEN.getQueue(), true);  //true 是否持久
    }

    //Direct交换机 起名：TestDirectExchange
    @Bean
    DirectExchange TokenDirectExchange() {
        return new DirectExchange(RabbitEnum.TOKEN.getExchange());
    }

    //绑定  将队列和交换机绑定, 并设置用于匹配键：TestDirectRouting
    @Bean
    Binding bindingTokenDirect() {
        return BindingBuilder.bind(TokenDirectQueue()).to(TokenDirectExchange()).with(RabbitEnum.TOKEN.getRouting());
    }

    //=====================================PV值添加机制
    @Bean
    public Queue ShopPVDirectQueue() {
        return new Queue(RabbitEnum.SHOP_PV.getQueue(), true);  //true 是否持久
    }

    //Direct交换机 起名：TestDirectExchange
    @Bean
    DirectExchange ShopPVDirectExchange() {
        return new DirectExchange(RabbitEnum.SHOP_PV.getExchange());
    }

    //绑定  将队列和交换机绑定, 并设置用于匹配键：TestDirectRouting
    @Bean
    Binding bindingShopPVDirect() {
        return BindingBuilder.bind(ShopPVDirectQueue()).to(ShopPVDirectExchange()).with(RabbitEnum.SHOP_PV.getRouting());
    }

    //=====================================推送添加机制
    @Bean
    public Queue PushDirectQueue() {
        return new Queue(RabbitEnum.PUSH.getQueue(), true);  //true 是否持久
    }

    //Direct交换机 起名：TestDirectExchange
    @Bean
    DirectExchange PushDirectExchange() {
        return new DirectExchange(RabbitEnum.PUSH.getExchange());
    }

    //绑定  将队列和交换机绑定, 并设置用于匹配键：TestDirectRouting
    @Bean
    Binding bindingPushDirect() {
        return BindingBuilder.bind(PushDirectQueue()).to(PushDirectExchange()).with(RabbitEnum.PUSH.getRouting());
    }

    //=====================================删除七牛文件
    @Bean
    public Queue DeleteQiniuFileDirectQueue() {
        return new Queue(RabbitEnum.DELETE_QINIU_FILE.getQueue(), true);  //true 是否持久
    }

    //Direct交换机 起名：TestDirectExchange
    @Bean
    DirectExchange DeleteQiniuFileDirectExchange() {
        return new DirectExchange(RabbitEnum.DELETE_QINIU_FILE.getExchange());
    }

    //绑定  将队列和交换机绑定, 并设置用于匹配键：TestDirectRouting
    @Bean
    Binding bindingDeleteQiniuFileDirect() {
        return BindingBuilder.bind(DeleteQiniuFileDirectQueue()).to(DeleteQiniuFileDirectExchange()).with(RabbitEnum.DELETE_QINIU_FILE.getRouting());
    }

    //=====================================提现到账户
    @Bean
    public Queue WithDrawToAccountDirectQueue() {
        return new Queue(RabbitEnum.WITHDRAW_TO_ACCOUNT.getQueue(), true);  //true 是否持久
    }

    //Direct交换机 起名：TestDirectExchange
    @Bean
    DirectExchange WithDrawToAccountDirectExchange() {
        return new DirectExchange(RabbitEnum.WITHDRAW_TO_ACCOUNT.getExchange());
    }

    //绑定  将队列和交换机绑定, 并设置用于匹配键：TestDirectRouting
    @Bean
    Binding bindingWithDrawToAccountDirect() {
        return BindingBuilder.bind(WithDrawToAccountDirectQueue()).to(WithDrawToAccountDirectExchange()).with(RabbitEnum.WITHDRAW_TO_ACCOUNT.getRouting());
    }
}